package com.ts.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class Date_to {
	public static String getTime() {
		Calendar now = Calendar.getInstance();
		String time = now.get(Calendar.YEAR) + ""
				+ (now.get(Calendar.MONTH) + 1) + ""
				+ now.get(Calendar.DAY_OF_MONTH) + ""
				+ now.get(Calendar.HOUR_OF_DAY) + "" + now.get(Calendar.MINUTE)
				+ "" + now.get(Calendar.SECOND);
		return time;
	}
	public static String getYear() {
		Calendar now = Calendar.getInstance();
		String time = now.get(Calendar.YEAR) + "";
		return time;
	}
	public static String make() {
		StringBuffer generateRandStr = new StringBuffer();
		Random rand = new Random();
		int length = 6;
		char ch;
		for (int i = 0; i < length; i++) {
			int randNum = Math.abs(rand.nextInt()) % 26 + 65;
			ch = (char) randNum;
			generateRandStr.append(ch);
		}
		return generateRandStr.toString();
	}

	public static String getDD() {
		// TODO Auto-generated method stub
		// SimpleDateFormat df = new
		// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//�������ڸ�ʽ
		// System.out.println(df.format(new Date()));// new Date()Ϊ��ȡ��ǰϵͳʱ��
		Date date = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd   HH:ss");
		System.out.println("time   now:" + df.format(date));
		Calendar canlandar = Calendar.getInstance();
		canlandar.setTime(date);
		canlandar.add(canlandar.DATE, -1
				* (canlandar.get(canlandar.DAY_OF_MONTH)));
		canlandar.add(canlandar.MONTH, 1);
		System.out.println("month   end:" + df.format(canlandar.getTime()));
		return df.format(canlandar.getTime());
	}
	
	public  String getDat() {
		// TODO Auto-generated method stub
		// SimpleDateFormat df = new
		// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//�������ڸ�ʽ
		// System.out.println(df.format(new Date()));// new Date()Ϊ��ȡ��ǰϵͳʱ��
		Date date = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd   HH:ss");
		System.out.println("time   now:" + df.format(date));
		Calendar canlandar = Calendar.getInstance();
		canlandar.setTime(date);
		canlandar.add(canlandar.DATE, -1
				* (canlandar.get(canlandar.DAY_OF_MONTH)));
		canlandar.add(canlandar.MONTH, 1);
		System.out.println("month   end:" + df.format(canlandar.getTime()));
		return df.format(canlandar.getTime());
	}
	public  String getDat2() {
		// TODO Auto-generated method stub
		// SimpleDateFormat df = new
		// SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//�������ڸ�ʽ
		// System.out.println(df.format(new Date()));// new Date()Ϊ��ȡ��ǰϵͳʱ��
		Date date = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println("time   now:" + df.format(date));
	
		return df.format(date);
	}
	public Date StringToDate2(String str) throws ParseException{
		 SimpleDateFormat   df   =new   SimpleDateFormat("yyyy-MM-dd hh:mm:ss");      
	     java.util.Date   cDate2   =   df.parse(str);      
	    java.sql.Date   dd2   =   new   java.sql.Date(cDate2.getTime());    
	    Date ta2 = new java.sql.Timestamp(dd2.getTime());   
	   return ta2;
	 }
 public Date StringToDate(String str) throws ParseException{
	 SimpleDateFormat   df   =new   SimpleDateFormat("yyyy-MM-dd");      
     java.util.Date   cDate2   =   df.parse(str);      
    java.sql.Date   dd2   =   new   java.sql.Date(cDate2.getTime());    
    Date ta2 = new java.sql.Timestamp(dd2.getTime());   
   return ta2;
 }
 public Date getDDD() throws ParseException{
	 SimpleDateFormat   df   =new   SimpleDateFormat("yyyy-MM-dd");      
     java.util.Date   cDate2   =   new Date();      
    java.sql.Date   dd2   =   new   java.sql.Date(cDate2.getTime());    
    Date ta2 = new java.sql.Timestamp(dd2.getTime());   
   return ta2;
 }
 
 public static String getTimes() {
		Calendar now = Calendar.getInstance();
		String time = now.get(Calendar.YEAR) + "-"
				+ (now.get(Calendar.MONTH) + 1) + "-"
				+ now.get(Calendar.DAY_OF_MONTH) + " "
				+ now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE)
				+ ":" + now.get(Calendar.SECOND);
		return time;
	}
 public static String getTimes2() {
		Calendar now = Calendar.getInstance();
		String time = now.get(Calendar.YEAR) + "-"
				+ (now.get(Calendar.MONTH) + 1) + "-"
				+ now.get(Calendar.DAY_OF_MONTH);
		return time;
	}
 public static String getTim() {
		Calendar now = Calendar.getInstance();
		String time = now.get(Calendar.YEAR) +"" 
				+ (now.get(Calendar.MONTH) + 1) +""
				+ now.get(Calendar.DAY_OF_MONTH);
		return time;
	}
 public static void main(String[] args) {
	System.out.println(getTim());
}
}
